package com.ruoyi.mp.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.system.MpClientCard;
import com.ruoyi.db.domain.system.PcCard;
import com.ruoyi.db.domain.web.MpClientSubCart;
import com.ruoyi.mp.annotion.Login;
import com.ruoyi.mp.annotion.LoginUser;
import com.ruoyi.mp.service.IMpClientCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 我的道具卡Controller
 * 
 * @author ruoyi
 * @date 2022-08-05
 */
@Api(value = "我的道具卡",tags ="我的道具卡")
@RestController
@RequestMapping("/smp/card")
public class MpClientCardController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(MpClientCardController.class);
    @Autowired
    private IMpClientCardService mpClientCardService;

    /**
     * 查询我的道具卡列表
     */
    @Login
    @ApiOperation(value = "查询我的道具卡列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientCard",value="我的道具卡",paramType="form")
    })
    @GetMapping("/list")
    public TableDataInfo list(MpClientCard mpClientCard,@LoginUser MpClient client)
    {
        try {
            startPage();
            mpClientCard.setClientId(client.getClientId());
            List<MpClientCard> list = mpClientCardService.selectMpClientCardList(mpClientCard);
            return getDataTable(list);
        }catch (Exception e){
            log.error("我的道具卡发生异常",e);
        }
        return null;
    }


    /**
     * 新增我的道具卡
     */
    @Login
    @ApiOperation(value = "购买道具卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientCard",value="我的道具卡",dataType="MpClientCard")
    })
    @PostMapping
    public AjaxResult add(@RequestBody MpClientCard mpClientCard, @LoginUser MpClient client)
    {
        try {
          mpClientCard.setClientId(client.getClientId());
          mpClientCardService.insertMpClientCard(mpClientCard,client);
            return AjaxResult.success("购买成功");
        }catch (Exception e){
            log.error("购买道具卡发生异常",e);
        }
        return AjaxResult.error("购买道具卡异常");
    }
    /**
     * 商城道具卡列表
     */

    @ApiOperation(value = "商城道具卡列表")
    @GetMapping("/card/list")
    public AjaxResult cardList()
    {
        try {
            List<PcCard>list = mpClientCardService.selectPcCardList();
            return AjaxResult.success(list);
        }catch (Exception e){
            log.error("查询道具卡发生异常",e);
        }
        return AjaxResult.error("查询道具卡异常");
    }

}
